#include "DevUtilsIos.h" 
#import <UIKit/UIKit.h>
#import "ads/GADInterstitial.h"
#import "AppController.h"


GADInterstitial *interstitial_=NULL;

#define ADUINIT_ID @"39e0d678fa99409d"

static GADBannerView* bannerView_=nil;
void DevUtilsIos::showBarAd(){
    
    if(bannerView_!=nil){ 
        bannerView_.delegate = nil;
        [bannerView_ release];
    }
    
    setAdSize(0, 0);
    
    
    GADRequest *request = [GADRequest request]; 
    request.testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];
    
    AppController *controller = [AppController sharedAppController];
    
    GADInterstitial* splashInterstitial_ = [[GADInterstitial alloc] init];
    
    splashInterstitial_.adUnitID = ADUINIT_ID;
    splashInterstitial_.delegate = controller;
    
    
    GADAdSize size=kGADAdSizeBanner;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        size=kGADAdSizeLeaderboard;
    }
    
    int frameHeight=controller.viewController.view.frame.size.height;
    
    CGPoint origin = CGPointMake(0.0,
                                 frameHeight -
                                 size.size.height);
    
    
    bannerView_ = [[GADBannerView alloc] initWithAdSize:size origin:origin];
    bannerView_.delegate = controller; 
    bannerView_.adUnitID =ADUINIT_ID;
     
    bannerView_.rootViewController = controller.viewController; 
    
    [bannerView_ loadRequest: request]; 
    
     
}

void DevUtilsIos::onBigAdClose(){
    showBarAd();
}

void DevUtilsIos::onBarShowed(){
    GADAdSize size=kGADAdSizeBanner;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        size=kGADAdSizeLeaderboard;
    }
    AppController *controller = [AppController sharedAppController];
    UIWindow *window=controller.window; 
    
    [window addSubview: bannerView_];
    setAdSize(size.size.width, 50);
    
}
   
void DevUtilsIos::showBigAd(){
    GADRequest *request = [GADRequest request];
  //  request.testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];
 
    AppController *controller = [AppController sharedAppController];
     
    GADInterstitial* splashInterstitial_ = [[GADInterstitial alloc] init];
    
    splashInterstitial_.adUnitID = ADUINIT_ID;
    splashInterstitial_.delegate = controller;
    UIWindow *window=controller.window;
    [splashInterstitial_ loadAndDisplayRequest:request
                                   usingWindow:window
                                  initialImage:[UIImage imageNamed:@"InitialImage"]];
    
    
}